//
//  RecommendViewController.swift
//  CWLiving
//
//  Created by 方正刚 on 2017/7/5.
//  Copyright © 2017年 方正刚. All rights reserved.
//

import UIKit

private let CYCLEVIEW_HEIGHT: CGFloat = SCREEN_WIDHT * 3 / 8

class RecommendViewController: BaseAnchorViewController {

    
    lazy var recommendVM: RecommendViewModel = RecommendViewModel()
    
    var recommendCycleView: RecommendCyleView = {
        let recommendCycleV = RecommendCyleView(frame: CGRect(x: 0, y: -CYCLEVIEW_HEIGHT, width: SCREEN_WIDHT, height: CYCLEVIEW_HEIGHT))
        
        return recommendCycleV

    }()
    
    

}


// MARK: - 设置UI
extension RecommendViewController {
   override func setupUI() {
    
    super.setupUI()
    
        // 添加collectionView
        
        view.addSubview(collectionView)
        
        collectionView.addSubview(recommendCycleView)
        
        collectionView.contentInset = UIEdgeInsetsMake(CYCLEVIEW_HEIGHT, 0, 0, 0)
    }
}

extension RecommendViewController {

    override func loadData() {
        super.loadData()
        baseVM = recommendVM
        recommendVM.requestData {
            self.collectionView.reloadData()
            self.didLoadData()
        }
        
        recommendVM.requestCycleData {
            
            self.recommendCycleView.cycleModels = self.recommendVM.Cycles
        }
    }

}



// MARK: - UICollectionViewDelegate
extension RecommendViewController: UICollectionViewDelegateFlowLayout {

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let group = recommendVM.anchorGroups[indexPath.section]
        
        let anchor = group.room_listModels[indexPath.item]
        
        if indexPath.section == 1 {
           let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PRETY_CELL, for: indexPath) as! CollectionPrettyCell
            cell.achor = anchor
            return cell
        }else {
            return super.collectionView(collectionView, cellForItemAt: indexPath)
        }
        
        
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        if indexPath.section == 1 {
            return CGSize(width: ITEM_WDITH, height: PRETYITEM_HEIGHT)
        }
        
            return CGSize(width: ITEM_WDITH, height: NORMOLITEM_HEIGHT)
        
    }
    
}




